// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

module.exports = {

    BIRDTYPE: cc.Enum({
        NORMAL: 0, //普通
        YWJBIRD: 1, //159中鸟
        SIGNALBIRD: 2, //一鸟全中
        BANKERBIRD: 3, //胡牌为庄
        WWBIRD: 4 //胡牌为庄
    }),

    TABLESTATE: cc.Enum({
        tsWaiting: 0, // 0 等待
        tsStart: 1, // 1 开始
        tsCallPoint: 2, // 2 叫分
        tsMaiPai: 3, // 3 发牌过程
        tsChaodi: 4, //4 叫地主过程（含抢地主）
        ts5Zhuguohe: 5, //4 叫地主过程（含抢地主）
        tsPlaying: 6, //4 叫地主过程（含抢地主）
        tsWaitForCallHu: 7, //等待其它玩家叫胡
        tsBalance: 8, //4 叫地主过程（含抢地主）
        tsDestory: 9 //被申请的解散
    }),
    GAMEID: cc.Enum({
        mj: 1,
        pdk: 3,
        zp: 6,
        xc: 7,
        whz: 8,
        nzl: 9,
        wfph: 11,
    }),

    MJGAMETYPE: cc.Enum({
        CSMJ: 0,
        ZZMJ: 1,
        HZMJ: 2,
        TDH: 3
    }),


    TVKey: cc.Enum({
        menu: 18,
        left: 1000,
        up: 1003,
        right: 1001,
        down: 1004,
        enter: 1005,
        back: 6
    }),

    LOGINTYPE: cc.Enum({
        WX: 0, //微信
        QQ: 1, //qq
        PSD: 2, //密码
        ALIPAY: 3 //支付宝
    }),

    GameConfig: {
        ISDEBUG: true,
        BASEGOLD: 0, //默认基础分 
        URL: "http://login.91shouy.com:8008",
        DOWNTIMEURL: 'http://login.91shouy.com/downtime.txt',
        VOICEURL: "http://wapgame.91shouy.com/sytx/onlineVoice.do?dbuserId=%d&voiceData=%s&valideKey=%s",

        WX_appID: 'wxfb4c6fec2a57e1b1',
        WX_secret: '1ad45b2f97e66507d8b6cd707878d780',

        versionName: "1.5.19.1", //版本号
        GAMEID: 0, //大合集



        RANKURL: "http://sdrweb.91shouy.com:8100/view/matchRank.html?id=%s",
        SHAREURL: "http://download.91shouy.com/down/index.html",
        AesKey: "suutihofmbwknl3m459qzu76rtb0ya7y",




        // window ID 
        WINDOW_MSG: 100, //对话框窗口
        WINDOW_CREATEROOM: 101, //创建规则
        WINDOW_ENTERROOM: 102,
        WINDOW_MENU: 103,
        WINDOW_LOADING: 104,
        WINDOW_RULE: 105, //规则面板
        WINDOW_GAMEINFO: 106, //游戏说明
        WINDOW_GUILD: 107,
        WINDOW_REQDISMISS: 108,
        WINDOW_SMILE: 109,
        WINDOW_SHARERECORD: 110,
        WINDOW_COPY: 111,
        WINDOW_SHARE: 112,
        WINDOW_CONTACT: 113,
        WINDOW_PKTEAMVOICE: 114,
        WINDOW_PROTOCOL: 115,
        WINDOW_FEEDBACK: 116,
        WINDOW_GIVEUP: 117,
        WINDOW_WFPHRULE: 118, //规则Lab面板


    },


    CREATEHUTYPE: {
        yizhihua: 0x0001, //一枝花
        jintongyunv: 0x0002, //金童玉女
        bubugao: 0x0004, //步步高
        santong: 0x0008, //三同
        midsixi: 0x0010, //中途四喜
        midliuliushun: 0x0020, //中途六六顺
        luanjianhu: 0x0040, //乱将胡
        jiajianghu: 0x0080, //假将胡
        qixiaodui: 0x0100, //七小对
        starthubird: 0x0200, //起手胡算不算鸟
        qiangganghu: 0x0400,
        birdNotNull: 0x0800, //鸟不打空
        kaisigang: 0x1000, //杠四个
        zimohu: 0x0001, //只能自摸
        hzzimohu: 0x0002, //有红中时只能自摸
        wei: 0x0004, //围
        hznoqianggaog: 0x0008, //红中不可抢杠
        singlepao: 0x2000, //单响炮
        goldbird: 0x4000 //金鸟
    },

    _netManger: null,
    _playerManager: null,
    _recordManager: null,
    ticket: null,
    addMsg: '', //点击加号时的消息
    noticeMsg: '',
    bannerMsg: '',
    matchInfo: [],
    gamematchInfo: [],
    isNeedFlushMatch: true,
    myLocal: '',
    soundType: -1,
    matchArr: '',
    shopType: 0,
    GAMEMAP: [],
    mIDInfo: '',
    mTrustName: '',


    //广播
    Notification: {
        _eventMap: [],
        on: function (type, cb, target) {
            if (this._eventMap[type] === undefined) {
                this._eventMap[type] = [];
            }
            this._eventMap[type].push({
                callback: cb,
                target: target
            });
        },

        emit: function (type, parameter) {
            var array = this._eventMap[type];
            if (array === undefined) return;

            array.forEach(element => {
                if (element)
                    element.callback.call(element.target, parameter);
            });

        },

        off: function (type, cb, target) {
            var array = this._eventMap[type];
            if (array === undefined) return;
            for (var i = 0; i < array.length; i++) {
                var item = array[i];
                if (item && item.callback === cb) {
                    if (target === undefined) {
                        array[i] = undefined;
                        array.splice(i, 1);
                        break;
                    }
                    if (item.target === target) {
                        array[i] = undefined;
                        array.splice(i, 1);
                        break;
                    }
                }
            }
        },

        offType: function (type) {
            this._eventMap[type] = undefined;
        }
    },

    RecordManager: function () {
        if (this._recordManager)
            return this._recordManager;
        this._netManger = new(require('RecordManager'));
        return this._netManger;
    },

    NetManager: function () {
        if (this._netManger)
            return this._netManger;
        this._netManger = new(require('NetManager'));
        return this._netManger;
    },

    PlayerManager: function () {
        if (this._playerManager)
            return this._playerManager;
        this._playerManager = new(require('PlayerManager'));
        return this._playerManager;
    },

    setTicket: function (ticket) {
        this.ticket = ticket;
    },

    getTicket: function () {
        return this.ticket;
    },

    getLocal: function () {
        return '';
    },

    setLocal: function (localinfo) {

    },

    getMJGameType: function (config) {
        switch (config.gametype) {
            case this.MJGAMETYPE.CSMJ:
                return '长沙麻将';
            case this.MJGAMETYPE.HZMJ:
                return '红中麻将';
            case this.MJGAMETYPE.ZZMJ:
                return '转转麻将';
            case this.MJGAMETYPE.TDH:
                return '推倒胡';
        }
        return '';
    },

    getGameNameByID: function (gameId, config) {
        if (gameId == GAMEID.mj) {
            return this.getMJGameType(config);
        } else if (gameId == GAMEID.zp) {
            return '字牌';
        } else if (gameId == GAMEID.xc) {
            return '湘潭消操';
        } else if (gameId == GAMEID.pdk) {
            return '跑的快';
        } else if (gameId == GAMEID.nzl) {
            return '牛转栏';
        } else if (gameId == GAMEID.whz) {
            return '歪胡子';
        } else if (gameId == GAMEID.wfph) {
            return '五福碰胡';
        }
    },

    dismissWindowByName: function (name) {
        cc.windowManager.dismissWindowByName(name);
    },

    showMessageBox: function (str, funOk, funCancel) {
        if (str == null)
            return;
        var msgWin = cc.windowManager.getWindowByName('msgwin');
        if (msgWin) {
            msgWin.showMsg(str, funOk, funCancel)
        } else {
            cc.windowManager.initWindow('msgwin', function (err, js) {
                if (err != null)
                    return;
                js.showMsg(str, funOk, funCancel)
            }.bind(this));
        }
    },

    showMessageBoxWithCancel: function (str, funOk) {
        var msgWin = cc.windowManager.getWindowByName('msgwin');
        if (msgWin) {
            msgWin.showWithCancelMsg(str, funOk);
        } else {
            cc.windowManager.initWindow('msgwin', function (err, js) {
                if (err != null)
                    return;
                js.showWithCancelMsg(str, funOk)
            }.bind(this));
        }
    },

    getRecordFromUrl: function (url, timeout, callback) {
        try {
            if (typeof (timeout) != 'number') {
                callback = timeout;
                timeout = -1;
            }
            var xhr = cc.loader.getXMLHttpRequest();
            xhr.open('GET', url, true);

            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status <= 207)) {
                    var httpStatus = xhr.statusText;
                    var response = xhr.responseText;
                    var resData;
                    try {
                        resData = {
                            success: true,
                            msg: response
                        };
                    } catch (ex) {
                        cc.error(ex);
                        resData = {
                            success: false,
                            msg: "网络连接失败"
                        };
                    }
                    callback(resData);
                }
            }.bind(this);
            if (timeout > 0) {
                xhr.timeout = timeout;
            } else {
                xhr.timeout = 15000;
            }
            xhr.onerror = function () {
                callback({
                    success: false,
                    msg: "网络连接失败"
                });
            }.bind(this);
            xhr.ontimeout = function () {
                cc.log('request ontimeout');
                callback({
                    success: false,
                    msg: "网络连接超时"
                });
            }.bind(this);
            xhr.send();
        } catch (ex) {
            callback({
                success: false,
                msg: ex
            });
        }
    },


    getdataFromUrl: function (url, timeout, callback) {
        try {

            if (typeof (timeout) != 'number') {
                callback = timeout;
                timeout = -1;
            }
            var xhr = cc.loader.getXMLHttpRequest();
            xhr.open('GET', url, true);
            xhr.setRequestHeader("cache-control", "no-cache");
            xhr.setRequestHeader("contentType", "text/html;charset=uft-8") //指定发送的编码  
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
            xhr.setRequestHeader("ticket", this.ticket);

            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status <= 207)) {
                    var httpStatus = xhr.statusText;
                    var response = xhr.responseText;
                    var resData;
                    try {
                        resData = {
                            success: true,
                            msg: response
                        };
                    } catch (ex) {
                        cc.error(ex);
                        resData = {
                            success: false,
                            msg: "网络连接失败"
                        };
                    }
                    callback(resData);
                }
            }.bind(this);
            if (timeout > 0) {
                xhr.timeout = timeout;
            } else {
                xhr.timeout = 15000;
            }
            xhr.onerror = function () {
                callback({
                    success: false,
                    msg: "网络连接失败"
                });
            }.bind(this);
            xhr.ontimeout = function () {
                cc.log('request ontimeout');
                callback({
                    success: false,
                    msg: "网络连接超时"
                });
            }.bind(this);
            xhr.send();
        } catch (ex) {
            callback({
                success: false,
                msg: ex
            });
        }
    },


    initGameMatchInfo: function (data) {
        this.matchInfo = [];
        this.isNeedFlushMatch = true;
        if (data) {
            var mathchItem = data;
            //转化
            for (var i = 0; i < mathchItem.length; i++) {
                var itemInfo = mathchItem[i];
                itemInfo.gameId = Number.parseInt(itemInfo.gameId);
                itemInfo.matchCode = Number.parseInt(itemInfo.matchCode);
                itemInfo.ownerId = Number.parseInt(itemInfo.ownerId);
                itemInfo.ruleType = JSON.parse(itemInfo.ruleType);
                itemInfo.ruleType.turn = itemInfo.gameCnt;
                var flag = false;
                for (var l = 0; l < this.matchInfo.length; l++) {
                    if (this.matchInfo[l].gameId == itemInfo.gameId && this.matchInfo[l].ownerId == itemInfo.ownerId) {
                        flag = true;
                        break;
                    }
                }
                if (!flag) {
                    var mathArr = {};
                    mathArr.gameId = itemInfo.gameId;
                    mathArr.ownerId = itemInfo.ownerId;
                    mathArr.guildName = itemInfo.guildName;
                    mathArr.item = [];
                    this.matchInfo.push(mathArr);
                }
            }

            for (var i = 0; i < this.matchInfo.length; i++) {
                for (var l = 0; l < mathchItem.length; l++) {
                    if (this.matchInfo[i].gameId == mathchItem[l].gameId && this.matchInfo[i].ownerId == mathchItem[l].ownerId) {
                        this.matchInfo[i].item.push({
                            ruleType: mathchItem[l].ruleType,
                            matchCode: mathchItem[l].matchCode,
                            matchName: mathchItem[l].matchName
                        });
                    }
                }
            }
        }
    },

    requestWithGameID: function (gameid, method, type, data, callback, isShowWindow, timeout) {
        try {
            var xhr = cc.loader.getXMLHttpRequest();
            var mHttpType = type;
            if ((typeof (type) == 'string') && (type.toUpperCase() == 'POST' || type.toUpperCase() == 'GET')) {

                if (type.toUpperCase() == 'POST') {
                    method = GameConfig.URL + '/' + method;
                } else {
                    method = this.GameConfig.URL + '/' + method + '?';
                    for (var key in data) {
                        method += key + '=' + data[key] + "&"
                    }

                    if (method.lastIndexOf('&') > 0) {
                        method = method.substring(0, method.lastIndexOf('&'));
                    }

                }

                if (isShowWindow == null) {
                    isShowWindow = true;
                }
            } else {
                mHttpType = 'POST';
                isShowWindow = callback;
                callback = data;
                data = type;
                method = this.GameConfig.URL + '/' + method;
                cc.log(this.GameConfig.URL + '/' + method);
                if (isShowWindow == null) {
                    isShowWindow = true;
                }

            }
            if (isShowWindow) {
                cc.windowManager.showWindowByNameWithDate('loadingwin', '请稍等,数据正在获取中...');
            }

            xhr.open(mHttpType, method, true);
            xhr.setRequestHeader("cache-control", "no-cache");
            xhr.setRequestHeader("contentType", "text/html;charset=uft-8") //指定发送的编码  
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
            xhr.setRequestHeader("ticket", this.ticket);
            xhr.setRequestHeader("gameid", gameid);


            if (timeout != null && typeof (timeout) == 'number') {
                xhr.timeout = timeout;
            }

            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status <= 207)) {
                    var httpStatus = xhr.statusText;
                    var response = xhr.responseText;
                    var resData;
                    try {
                        resData = JSON.parse(response);
                    } catch (ex) {
                        cc.error(ex);
                        resData = {
                            success: false,
                            msg: "网络连接失败"
                        };
                    }
                    if (isShowWindow) {
                        cc.windowManager.dismissWindowByName('loadingwin');
                    }

                    if (resData.errcode == 100) {
                        cc.windowManager.dismiss();
                        this.showMessageBox(resData.msg);
                        cc.director.loadScene('hall');
                    } else {
                        callback(resData);
                    }
                } else {
                    // cc.log('xhr.readyState = ' + xhr.readyState);
                    // callback({
                    //     success: false,
                    //     msg: "网络连接失败"
                    // });
                }
            }.bind(this);
            if (data.timeout != null) {
                xhr.timeout = data.timeout;
                delete data.timeout;
            } else {
                xhr.timeout = 5000;
            }
            xhr.onerror = function () {
                if (isShowWindow) {
                    cc.windowManager.dismissWindowByName('loadingwin');
                }
                callback({
                    success: false,
                    msg: "网络连接失败"
                });
            }.bind(this);
            xhr.ontimeout = function () {
                cc.log('request ontimeout');
                if (isShowWindow) {
                    cc.windowManager.dismissWindowByName('loadingwin');
                }
                callback({
                    success: false,
                    msg: "网络连接超时"
                });
            }.bind(this);
            if (mHttpType == 'GET') {
                xhr.send();
            } else {
                xhr.send(JSON.stringify(data));
            }
        } catch (ex) {
            cc.log(ex);
        }
    },

    request: function (method, type, data, callback, isShowWindow, timeout) {
        this.requestWithGameID(0, method, type, data, callback, isShowWindow, timeout);
    },

    startlogin: function (info, noNeedCheck, fb) {
        //提交用户登陆信息
        if (cc.sys.os == cc.sys.OS_ANDROID) {
            info.platform = 'android';
        } else if (cc.sys.os == cc.sys.OS_IOS) {
            info.platform = 'ios';
        } else {
            info.platform = 'web';
        }

        if (noNeedCheck != null && typeof (noNeedCheck) != 'boolean') {
            fb = noNeedCheck;
            noNeedCheck = false;
        }

        this.request("login", 'GET', info, function (data) {
            if (data.success) {
                if (data.player) {
                    this.ticket = data.player.ticket;
                    this.addMsg = '';
                    if (data.addmsg) {
                        this.addMsg = data.addmsg;
                    }
                    this.bannerMsg = '';
                    if (data.activity) {
                        this.bannerMsg = data.activity;
                    }
                    this.noticeMsg = '';
                    if (data.msg) {
                        this.noticeMsg = data.msg;
                    }
                    // NetCenterManager.setUrl(data.center);
                    this.matchArr = '';
                    if (data.matchArr) {
                        this.matchArr = data.matchArr;
                    }

                    if (this.PlayerManager().m_MySelf == null) {
                        this.PlayerManager().newPlayer(data.player);
                    } else {
                        this.PlayerManager().m_MySelf.init(data.player);
                    }

                    this.mIDInfo = '';
                    this.mTrustName = '';
                    if (data.player.trushName && data.player.trushName != 'null' && data.player.trushName != 'undefined') {
                        this.mTrustName = data.player.trushName;
                    }

                    if (data.player.Identification && data.player.Identification != 'null' && data.player.Identification != 'undefined') {
                        this.mIDInfo = data.player.Identification;
                    }


                    if (data.shoptype) {
                        this.shopType = Number.parseInt(data.shoptype);
                    } else {
                        this.shopType == 0;
                    }

                    if (data.GameMAP) {
                        this.GAMEMAP = data.GameMAP;
                    } else {
                        this.GAMEMAP = [];
                    }



                    this.initGameMatchInfo(data.player.matchItem);
                    this.PlayerManager().m_MySelf.tableInfo = data.player.table;

                    cc.sys.localStorage.setItem('account', info.account);
                    cc.sys.localStorage.setItem('password', '');
                    cc.sys.localStorage.setItem('acctype', this.LOGINTYPE.WX);
                    cc.sys.localStorage.setItem('lastlogin', parseInt(new Date() / 1000));
                    if (info.type == this.LOGINTYPE.PSD) {
                        cc.sys.localStorage.setItem('password', info.password);
                        cc.sys.localStorage.setItem('acctype', this.LOGINTYPE.PSD);
                    }
                    if (data.reconnect) {
                        //需要重连 
                        this.NetManager().connect(data.url, data.gameid, function (state) {
                            if (state == 'connect') {
                                //重连
                                this.NetManager().sendPacket('BACKGAME', {
                                    id: data.id,
                                    tid: data.tid,
                                    ticket: this.getTicket()
                                });
                            }
                        }.bind(this));
                    } else {
                        this.dismissWindowByName('loadingwin');
                        if (fb) {
                            fb('hall');
                        }
                        //保存数据 
                    }
                }

            } else {
                this.dismissWindowByName('loadingwin');
                if (noNeedCheck) {
                    this.showMessageBoxWithCancel(data.msg + ',是否重试？', function () {
                        this.startlogin(info, true, fb);
                    }.bind(this));
                } else {
                    this.getRecordFromUrl(GameConfig.DOWNTIMEURL, function (notice) {
                        if (notice.success) {
                            this.showMessageBox(notice.msg);
                        } else {
                            this.showMessageBoxWithCancel(data.msg + ',是否重试？', function () {
                                this.startlogin(info, true, fb);
                            }.bind(this));
                        }
                    }.bind(this));
                }
            }
        }.bind(this), false, 10000);
    },


    CheckWordFlag: function (flag, type) {
        if (flag == null)
            return false;

        if ((flag & type) == type) {
            return true;
        }
        return false;
    },

    getMJConfig: function (config, isSmart, flag) {
        var ruleStr = '';

        if (isSmart == null || isSmart == false) {
            if (config.gametype != this.MJGAMETYPE.CSMJ) {
                ruleStr += this.getMJGameType(config) + "\n";
            }
        }

        if (flag == null) {
            flag = ' ';
        }

        if (config.playnums == 3) {
            ruleStr += '三人玩法\n';
        } else if (config.playnums == 2) {
            ruleStr += '两人玩法\n';
        }

        if (config.gametype == this.MJGAMETYPE.HZMJ || config.gametype == this.MJGAMETYPE.ZZMJ) {
            if (this.CheckWordFlag(config.hutype, this.CREATEHUTYPE.zimohu)) {
                ruleStr += '只能自摸\n';
            } else if (this.CheckWordFlag(config.hutype, this.CREATEHUTYPE.hzzimohu)) {
                ruleStr += '红中自摸\n';
            } else {
                ruleStr += '可接炮\n';
            }
        }

        if (config.isPiao) {
            ruleStr += '飘分 ';
        }

        if (config.scoretype == 0) {
            ruleStr += '不封顶\n';
        } else {
            ruleStr += config.scoretype + '封顶\n';
        }
        if (config.isRandom) {
            ruleStr += '每局随机换位\n';
        }

        if (config.isKan3Pei) {
            ruleStr += '放三坎包赔\n';
        }

        var birdNums = (config.birdtype & 0x0f);
        var birdType = (config.birdtype >> 4);
        var isAdd = true;
        if (birdType >= 8) {
            birdType -= 8;
            isAdd = false;
        }
        switch (birdType) {
            case this.BIRDTYPE.NORMAL:
                ruleStr += '庄闲分';
                break;
            case this.BIRDTYPE.YWJBIRD:
                ruleStr += '159中鸟';
                break;
            case this.BIRDTYPE.SIGNALBIRD:
                ruleStr += '一鸟全中\n';
                break;
            case this.BIRDTYPE.BANKERBIRD:
                ruleStr += '胡牌为庄';
                break;
            case this.BIRDTYPE.WWBIRD:
                ruleStr += '窝窝鸟\n';
                break;
        }



        if (birdNums > 0) {
            if (!isAdd) {
                ruleStr += ' 乘法'
            } else if (birdType != this.BIRDTYPE.SIGNALBIRD && birdType != this.BIRDTYPE.WWBIRD) {
                ruleStr += ' 加法'
            }

            if (birdType != this.BIRDTYPE.SIGNALBIRD && birdType != this.BIRDTYPE.WWBIRD) {
                ruleStr += birdNums + '鸟\n';
            }

            if (this.CheckWordFlag(config.hutype, this.CREATEHUTYPE.birdNotNull)) {
                ruleStr += '鸟不打空 \n';
            }
        } else {
            ruleStr += ' 不扎鸟\n';
        }



        if (config.gametype == this.MJGAMETYPE.CSMJ) {
            if (config.hutype != null && config.hutype != 0) {
                if (this.CheckWordFlag(config.hutype, this.CREATEHUTYPE.kaisigang)) {
                    ruleStr += '开四杠 \n';
                }

                if (this.CheckWordFlag(config.hutype, this.CREATEHUTYPE.starthubird)) {
                    ruleStr += '起手胡算鸟\n';
                }

                if (this.CheckWordFlag(config.hutype, this.CREATEHUTYPE.luanjianhu)) {
                    ruleStr += '乱将胡\n';
                }

                if (this.CheckWordFlag(config.hutype, this.CREATEHUTYPE.jiajianghu)) {
                    ruleStr += '假将胡\n';
                }

                if (this.CheckWordFlag(config.hutype, this.CREATEHUTYPE.yizhihua)) {
                    ruleStr += '一枝花\n';
                }

                if (this.CheckWordFlag(config.hutype, this.CREATEHUTYPE.bubugao)) {
                    ruleStr += '步步高\n';
                }

                if (this.CheckWordFlag(config.hutype, this.CREATEHUTYPE.santong)) {
                    ruleStr += '三同\n';
                }

                if (this.CheckWordFlag(config.hutype, this.CREATEHUTYPE.jintongyunv)) {
                    ruleStr += '金童玉女\n';
                }
                if (this.CheckWordFlag(config.hutype, this.CREATEHUTYPE.midsixi)) {
                    ruleStr += '中途四喜\n';
                }

                if (this.CheckWordFlag(config.hutype, this.CREATEHUTYPE.midliuliushun)) {
                    ruleStr += '中途六六顺\n';
                }
            }
        } else if (config.gametype != this.MJGAMETYPE.CSMJ) {

            if (birdNums > 0) {
                if (this.CheckWordFlag(config.hutype, this.CREATEHUTYPE.goldbird)) {
                    ruleStr += '金鸟\n';
                }

            }

            if (this.CheckWordFlag(config.hutype, this.CREATEHUTYPE.qixiaodui)) {
                ruleStr += '可胡七对\n';
            }
            if (this.CheckWordFlag(config.hutype, this.CREATEHUTYPE.qiangganghu)) {
                ruleStr += '可抢杠胡\n';
            }
            if (this.CheckWordFlag(config.hutype, this.CREATEHUTYPE.hznoqianggaog)) {
                ruleStr += '有红中不可抢杠\n';
            }
            if (this.CheckWordFlag(config.hutype, this.CREATEHUTYPE.wei)) {
                ruleStr += '加围\n';
            }

            if (config.playnums != 2)
                if (this.CheckWordFlag(config.hutype, this.CREATEHUTYPE.singlepao)) {
                    ruleStr += '单响炮\n';
                }

        }
        if (isSmart) {
            ruleStr = ruleStr.replace(/\n/g, flag);
        }
        return ruleStr;
    }
};